﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using System.Speech.Recognition;
using System.Runtime.InteropServices;

namespace University.Workshop.WinApp
{
    public partial class Main : Form
    {
        public static string[] userMenu= new string[4];
        //SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
        //public Form instance;
        public Main()
        {
            InitializeComponent();
            Singleton.Instance.valid = true;            
        }

        //private void IssuePermits()
        //{
        //    newUserToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "RegisterUser");
        //    searchUserToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "SearchUser");
        //    newPatientToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "NewPatient");
        //    searchPatientToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "SearchPatient");
        //    newAppointmentToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "NewAppointment");
        //    todayAppointmentToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "TodayAppointment");
        //    newProductToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "NewProduct");
        //    searchProductToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "SearchProduct");
        //    createRoleToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "CreateAnEditRole");
        //    assignRoleToolStripMenuItem.Enabled = RoleFacade.PermissionUser(userMenu[3], "AssignRole");
        //    buttonAgenda.Enabled = RoleFacade.PermissionUser(userMenu[3], "AgendaDoctor");

        //}        

        private void Main_Load(object sender, EventArgs e)
        {
            LoginUser login = new LoginUser();
            login.ShowDialog();
            string date = DateTime.Today.ToLongDateString();
            toolStripStatusLabelUser.Text = "Welcome " + userMenu[0] +" "+userMenu[1] +"            "+date;
            //IssuePermits();
        }

        private void exitAplicationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void exitSessionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripStatusLabelUser.Text = "System Ucb";
            LoginUser login = new LoginUser();
            login.ShowDialog();
            string date = DateTime.Today.ToLongDateString();
            toolStripStatusLabelUser.Text = "Welcome " + userMenu[0] + " "+ userMenu[1]+"            " + date;
            //IssuePermits();
        }

        private void newUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && newUserToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new RegisterUser();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void searchUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && searchUserToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new SearchUser();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void newPatientToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && newPatientToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new NewPatient();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }

        }

        private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && changePasswordToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new ChangePasswordUser(userMenu[2]);
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void searchPatientToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && searchPatientToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new SearchPatient();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void newAppointmentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && newAppointmentToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new NewAppointment();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void buttonAgenda_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && buttonAgenda.Enabled == true)
            {
                Form ChildrenFrom = new AgendaDoctor();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }     
        }

        private void todayAppointmentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && todayAppointmentToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new TodayAppointment();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }    
        }

        private void newProductToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && newProductToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new NewProduct();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }  
        }

        private void searchProductToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && searchProductToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new SearchProduct();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void createRoleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && createRoleToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new CreateAnEditRole();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void assignRoleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && assignRoleToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new AssignRole();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }

        private void createNoteBookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Singleton.Instance.isValid() && assignRoleToolStripMenuItem.Enabled == true)
            {
                Form ChildrenFrom = new ViewNoteBook();
                ChildrenFrom.MdiParent = this;
                ChildrenFrom.Show();
                Singleton.Instance.valid = false;
            }
        }
        //private void enableToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        _recognizer.SetInputToDefaultAudioDevice();
        //        _recognizer.LoadGrammar(MiGramatica());
        //        _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
        //        _recognizer.RecognizeAsync(RecognizeMode.Multiple);
        //    }
        //    catch (Exception err)
        //    {
        //        MessageBox.Show(err.ToString());
        //    }
        //}

        //private static Grammar MiGramatica()
        //{
        //    Grammar miGramatica = new Grammar(AppDomain.CurrentDomain.BaseDirectory + "//Grammar.xml");
        //    miGramatica.Name = "My Grammar";
        //    return miGramatica;
        //}

        //private void RunCommand(string command)
        //{
        //    switch (command)
        //    {
        //        case "usersToolStripMenuItem"://users
        //            {
        //                int x = usersToolStripMenuItem.Bounds.X + usersToolStripMenuItem.Size.Width / 2;
        //                int y = usersToolStripMenuItem.Bounds.Y + usersToolStripMenuItem.Size.Height + 15;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "newUserToolStripMenuItem"://newUser
        //            {
        //                newUserToolStripMenuItem_Click(this, new EventArgs());

        //            } break;

        //        case "patientToolStripMenuItem"://patient
        //            {
        //                int x = patientToolStripMenuItem.Bounds.X + patientToolStripMenuItem.Size.Width / 2;
        //                int y = patientToolStripMenuItem.Bounds.Y + patientToolStripMenuItem.Size.Height + 15;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "agendaToolStripMenuItem"://agenda
        //            {
        //                int x = agendaToolStripMenuItem.Bounds.X + agendaToolStripMenuItem.Size.Width / 2;
        //                int y = agendaToolStripMenuItem.Bounds.Y + agendaToolStripMenuItem.Size.Height + 15;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "productToolStripMenuItem"://producto
        //            {
        //                int x = productToolStripMenuItem.Bounds.X + productToolStripMenuItem.Size.Width / 2;
        //                int y = productToolStripMenuItem.Bounds.Y + productToolStripMenuItem.Size.Height + 15;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "sessionToolStripMenuItem"://sistema
        //            {
        //                int x = sessionToolStripMenuItem.Bounds.X + sessionToolStripMenuItem.Size.Width / 2;
        //                int y = sessionToolStripMenuItem.Bounds.Y + sessionToolStripMenuItem.Size.Height + 15;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "cashToolStripMenuItem"://cuentas
        //            {
        //                int x = cashToolStripMenuItem.Bounds.Location.X + cashToolStripMenuItem.Width / 2;
        //                int y = cashToolStripMenuItem.Bounds.Location.Y + cashToolStripMenuItem.Height + 8;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "newPatientToolStripMenuItem"://nuevo paciente
        //            {
        //                newPatientToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "newAppointmentToolStripMenuItem"://nueva cita
        //            {
        //                newAppointmentToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "newProductToolStripMenuItem"://nuevo producto
        //            {
        //                newProductToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "searchUserToolStripMenuItem"://buscar Usuario
        //            {
        //                searchUserToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "searchPatientToolStripMenuItem"://buscar paciente
        //            {
        //                searchPatientToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "searchProductToolStripMenuItem"://buscar producto
        //            {
        //                searchProductToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "todayAppointmentToolStripMenuItem"://citas de hoy 
        //            {
        //                todayAppointmentToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "exitSessionToolStripMenuItem"://cerrar sesion 
        //            {
        //                exitSessionToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "changePasswordToolStripMenuItem"://cambiar password
        //            {
        //                changePasswordToolStripMenuItem_Click(this, new EventArgs());
        //            } break;


        //        case "exitAplicationToolStripMenuItem"://cerrar programa 
        //            {
        //                exitAplicationToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "close"://cerrar cualquier ventana 
        //            {
        //                instance.Close();
        //                Singleton.Instance.valid = true;
        //            } break;

        //        case "createAndEditRolesToolStripMenuItem"://Roles
        //            {
        //                int x = createAndEditRolesToolStripMenuItem.Bounds.Location.X + createAndEditRolesToolStripMenuItem.Width + 100;
        //                int y = createAndEditRolesToolStripMenuItem.Bounds.Location.Y + createAndEditRolesToolStripMenuItem.Height + 35;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "createRoleToolStripMenuItem"://crear roles
        //            {
        //                createRoleToolStripMenuItem_Click(this, new EventArgs());
        //            } break;
                    

        //        case "assignRoleToolStripMenuItem"://asignar roles
        //            {
        //                assignRoleToolStripMenuItem_Click(this, new EventArgs());
        //            } break;


        //        case "jpderToolStripMenuItem"://cuentas por pagar
        //            {
        //                jpderToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "accountsReceivableToolStripMenuItem"://cuentas por cobrar
        //            {
        //                accountsReceivableToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "voiceControlToolStripMenuItem"://reconocimiento de voz
        //            {
        //                int x = voiceControlToolStripMenuItem.Bounds.Location.X + voiceControlToolStripMenuItem.Width / 2;
        //                int y = voiceControlToolStripMenuItem.Bounds.Location.Y + voiceControlToolStripMenuItem.Height + 8;
        //                Cursor.Position = new Point(x, y);
        //                DoClick(x, y);
        //            } break;

        //        case "enableToolStripMenuItem"://habilitar comandos de voz
        //            {
        //                enableToolStripMenuItem_Click(this, new EventArgs());
        //            } break;

        //        case "disableToolStripMenuItem"://deshabilitar comandos de voz
        //            {
        //                disableToolStripMenuItem_Click(this, new EventArgs());
        //            } break;
        //    }
        //}

        //public void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        //{
        //    foreach (RecognizedWordUnit word in e.Result.Words)
        //    {
        //        try
        //        {
        //            string command = ValidateCommands.TranslateCommand(word.Text);
        //            if (command != "")
        //            {
        //                RunCommand(command);
        //            }
        //        }
        //        catch (Exception err)
        //        {
        //            MessageBox.Show(err.ToString());
        //        }
        //    }
        //}

        //private void DoClick(int x, int y)
        //{
        //    mouse_event(MouseEventType.LeftDown, x, y, 0, 0);
        //    mouse_event(MouseEventType.LeftUp, x, y, 0, 0);
        //}

        //private void disableToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    _recognizer.RecognizeAsyncCancel();
        //}

        //[DllImport("user32.dll")]
        //public static extern void mouse_event(MouseEventType dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
        //public enum MouseEventType : int
        //{
        //    LeftDown = 0x02,
        //    LeftUp = 0x04,
        //    RightDown = 0x08,
        //    RightUp = 0x10
        //}   

    }
    sealed class Singleton
    {
        private Singleton() { }
        public static readonly Singleton Instance = new Singleton();
        public bool valid;
        public bool isValid()
        {
            return valid;
        }

    }
}
